﻿using System.Diagnostics;
using estoque.ViewModel;

namespace estoque
{
    internal static class TimeMeasure
    {
        private static Stopwatch sw = new Stopwatch();

        private static TaskVM currentTask;

        internal static void Stop(TaskVM task)
        {
            sw.Stop();
            currentTask.ProcessingTime = currentTask.ProcessingTime.Add(sw.Elapsed);
            currentTask.IsRunning = false;
            currentTask = null;
        }

        internal static void Start(TaskVM task)
        {
            if (currentTask != null)
            {
                Stop(currentTask);
            }

            currentTask = task;
            currentTask.IsRunning = true;
            sw.Reset();
            sw.Start();
        }
    }
}